package interfaz;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.JPasswordField;

import java.awt.Dimension;

import javax.swing.JComboBox;
import javax.swing.border.LineBorder;

public class Registro implements IVista{


    private JFrame frmRegistro;
    public JFrame getFrmRegistro() {
		return frmRegistro;
	}

	private JTextField txtNombre;
    private JTextField txtDNI;
    private JTextField txtApellidos;
    private JTextField txtTelefono;
    private JTextField txtDireccion;
    private JTextField txtProvincia;
    private JTextField txtCodPostal;
    private JTextField txtEmail;
    private JTextField txtUsuario;
	private JPasswordField txtPass1;
	private JPasswordField txtPass2;
	private JComboBox<String> cmbTipoUsuario;
	private JButton btnAceptar;
	private JButton btnCancelar;
	private JPanel pnlRegistro;

	

	/**
	 * @wbp.parser.constructor
	 */
    public Registro() {
        initialize(false,false,0);
    }
    
    public Registro(boolean mostrarCmbTipoUsuario){
    	initialize(mostrarCmbTipoUsuario, false,0);
    }
    
   
    
    public Registro(boolean mostrarCmbTipoUsuario, boolean modificar, int idUsuario){
    	initialize(mostrarCmbTipoUsuario, modificar, idUsuario);
    }
    

    /**
     * Initialize the contents of the frame.
     */
    private void initialize(boolean mostrarCmbTipoUsuario,boolean modificar, int idUsuario) {
            frmRegistro = new JFrame();
            frmRegistro.setMinimumSize(new Dimension(0, 1000));
            frmRegistro.setMaximumSize(new Dimension(2147483647, 600));
            frmRegistro.getContentPane().setBackground(Color.WHITE);
            frmRegistro.setBackground(Color.WHITE);
            frmRegistro.setTitle("Registro");
            frmRegistro.setBounds(0, 0, 537, 640);
            frmRegistro.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
           
            GridBagLayout gridBagLayout = new GridBagLayout();
            gridBagLayout.columnWidths = new int[]{397, 0};
            gridBagLayout.rowHeights = new int[]{651, 0};
            gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
            gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
            frmRegistro.getContentPane().setLayout(gridBagLayout);
            
            pnlRegistro = new JPanel();
            pnlRegistro.setBackground(Color.WHITE);
            GridBagConstraints gbc_pnlRegistro = new GridBagConstraints();
            gbc_pnlRegistro.fill = GridBagConstraints.BOTH;
            gbc_pnlRegistro.gridx = 0;
            gbc_pnlRegistro.gridy = 0;
            frmRegistro.getContentPane().add(pnlRegistro, gbc_pnlRegistro);
            GridBagLayout gbl_pnlRegistro = new GridBagLayout();
            gbl_pnlRegistro.columnWidths = new int[]{10, 319, 10, 0};
            gbl_pnlRegistro.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
            gbl_pnlRegistro.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
            gbl_pnlRegistro.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE};
            pnlRegistro.setLayout(gbl_pnlRegistro);
            
            cmbTipoUsuario = new JComboBox<String>();
            GridBagConstraints gbc_cmbTipoUsuario = new GridBagConstraints();
            gbc_cmbTipoUsuario.anchor = GridBagConstraints.WEST;
            gbc_cmbTipoUsuario.insets = new Insets(0, 0, 5, 5);
            gbc_cmbTipoUsuario.gridx = 1;
            gbc_cmbTipoUsuario.gridy = 0;
            
            if(mostrarCmbTipoUsuario){
            	cmbTipoUsuario.addItem("Tecnico");
            	cmbTipoUsuario.addItem("Cliente");
            	pnlRegistro.add(cmbTipoUsuario, gbc_cmbTipoUsuario);
        	}
           
            
            JPanel pnlDatosPersonales = new JPanel();
            pnlDatosPersonales.setMinimumSize(new Dimension(0, 0));
            GridBagConstraints gbc_pnlDatosPersonales = new GridBagConstraints();
            gbc_pnlDatosPersonales.fill = GridBagConstraints.BOTH;
            gbc_pnlDatosPersonales.insets = new Insets(0, 0, 5, 5);
            gbc_pnlDatosPersonales.gridx = 1;
            gbc_pnlDatosPersonales.gridy = 2;
            pnlRegistro.add(pnlDatosPersonales, gbc_pnlDatosPersonales);
            pnlDatosPersonales.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Datos personales", TitledBorder.LEFT, TitledBorder.TOP, null, null));
            pnlDatosPersonales.setBackground(Color.WHITE);
            GridBagLayout gbl_pnlDatosPersonales = new GridBagLayout();
            gbl_pnlDatosPersonales.columnWidths = new int[]{30, 0, 0, 0, 0, 0};
            gbl_pnlDatosPersonales.rowHeights = new int[]{15, 0, 10, 0, 10, 0, 0, 0};
            gbl_pnlDatosPersonales.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE};
            gbl_pnlDatosPersonales.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
            pnlDatosPersonales.setLayout(gbl_pnlDatosPersonales);
            
            JLabel lblNombre = new JLabel("Nombre");
            GridBagConstraints gbc_lblNombre = new GridBagConstraints();
            gbc_lblNombre.anchor = GridBagConstraints.WEST;
            gbc_lblNombre.insets = new Insets(0, 0, 5, 5);
            gbc_lblNombre.gridx = 1;
            gbc_lblNombre.gridy = 1;
            pnlDatosPersonales.add(lblNombre, gbc_lblNombre);
            
            txtNombre = new JTextField();
            GridBagConstraints gbc_txtNombre = new GridBagConstraints();
            gbc_txtNombre.fill = GridBagConstraints.BOTH;
            gbc_txtNombre.insets = new Insets(0, 0, 5, 5);
            gbc_txtNombre.gridx = 3;
            gbc_txtNombre.gridy = 1;
            pnlDatosPersonales.add(txtNombre, gbc_txtNombre);
            txtNombre.setColumns(10);
            
            JLabel lblApellidos = new JLabel("Apellidos");
            GridBagConstraints gbc_lblApellidos = new GridBagConstraints();
            gbc_lblApellidos.anchor = GridBagConstraints.WEST;
            gbc_lblApellidos.insets = new Insets(0, 0, 5, 5);
            gbc_lblApellidos.gridx = 1;
            gbc_lblApellidos.gridy = 3;
            pnlDatosPersonales.add(lblApellidos, gbc_lblApellidos);
            
            txtApellidos = new JTextField();
            GridBagConstraints gbc_txtApellidos = new GridBagConstraints();
            gbc_txtApellidos.insets = new Insets(0, 0, 5, 5);
            gbc_txtApellidos.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtApellidos.gridx = 3;
            gbc_txtApellidos.gridy = 3;
            pnlDatosPersonales.add(txtApellidos, gbc_txtApellidos);
            txtApellidos.setColumns(10);
            
            JLabel lblDnicif = new JLabel("DNI/CIF");
            GridBagConstraints gbc_lblDnicif = new GridBagConstraints();
            gbc_lblDnicif.anchor = GridBagConstraints.WEST;
            gbc_lblDnicif.insets = new Insets(0, 0, 5, 5);
            gbc_lblDnicif.gridx = 1;
            gbc_lblDnicif.gridy = 5;
            pnlDatosPersonales.add(lblDnicif, gbc_lblDnicif);
            
            txtDNI = new JTextField();
            GridBagConstraints gbc_txtDNI = new GridBagConstraints();
            gbc_txtDNI.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtDNI.insets = new Insets(0, 0, 5, 5);
            gbc_txtDNI.gridx = 3;
            gbc_txtDNI.gridy = 5;
            pnlDatosPersonales.add(txtDNI, gbc_txtDNI);
            txtDNI.setColumns(10);
            
            JPanel pnlDatosContacto = new JPanel();
            GridBagConstraints gbc_pnlDatosContacto = new GridBagConstraints();
            gbc_pnlDatosContacto.fill = GridBagConstraints.BOTH;
            gbc_pnlDatosContacto.insets = new Insets(0, 0, 5, 5);
            gbc_pnlDatosContacto.gridx = 1;
            gbc_pnlDatosContacto.gridy = 4;
            pnlRegistro.add(pnlDatosContacto, gbc_pnlDatosContacto);
            pnlDatosContacto.setBorder(new TitledBorder(null, "Datos de contacto", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            pnlDatosContacto.setBackground(Color.WHITE);
            GridBagLayout gbl_pnlDatosContacto = new GridBagLayout();
            gbl_pnlDatosContacto.columnWidths = new int[]{ 30,  0,  100, 115, 0, 0};
            gbl_pnlDatosContacto.rowHeights = new int[]{ 15,  0,  15,  0,  15,  0,  15, 0, 15,  0, 15};
            gbl_pnlDatosContacto.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
            gbl_pnlDatosContacto.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
            pnlDatosContacto.setLayout(gbl_pnlDatosContacto);
            
            JLabel lblEmail = new JLabel("Email");
            GridBagConstraints gbc_lblEmail = new GridBagConstraints();
            gbc_lblEmail.anchor = GridBagConstraints.WEST;
            gbc_lblEmail.insets = new Insets(0, 0, 5, 5);
            gbc_lblEmail.gridx = 1;
            gbc_lblEmail.gridy = 1;
            pnlDatosContacto.add(lblEmail, gbc_lblEmail);
            
            txtEmail = new JTextField();
            GridBagConstraints gbc_txtEmail = new GridBagConstraints();
            gbc_txtEmail.gridwidth = 3;
            gbc_txtEmail.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtEmail.insets = new Insets(0, 0, 5, 5);
            gbc_txtEmail.gridx = 2;
            gbc_txtEmail.gridy = 1;
            pnlDatosContacto.add(txtEmail, gbc_txtEmail);
            txtEmail.setColumns(10);
            
            JLabel lblTelefono = new JLabel("Tel\u00E9fono");
            GridBagConstraints gbc_lblTelefono = new GridBagConstraints();
            gbc_lblTelefono.anchor = GridBagConstraints.WEST;
            gbc_lblTelefono.insets = new Insets(0, 0, 5, 5);
            gbc_lblTelefono.gridx = 1;
            gbc_lblTelefono.gridy = 3;
            pnlDatosContacto.add(lblTelefono, gbc_lblTelefono);
            
            txtTelefono = new JTextField();
            GridBagConstraints gbc_txtTelefono = new GridBagConstraints();
            gbc_txtTelefono.gridwidth = 3;
            gbc_txtTelefono.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtTelefono.anchor = GridBagConstraints.SOUTH;
            gbc_txtTelefono.insets = new Insets(0, 0, 5, 5);
            gbc_txtTelefono.gridx = 2;
            gbc_txtTelefono.gridy = 3;
            pnlDatosContacto.add(txtTelefono, gbc_txtTelefono);
            txtTelefono.setColumns(10);
            
            JLabel lblDireccion = new JLabel("Direcci\u00F3n");
            GridBagConstraints gbc_lblDireccion = new GridBagConstraints();
            gbc_lblDireccion.anchor = GridBagConstraints.WEST;
            gbc_lblDireccion.insets = new Insets(0, 0, 5, 5);
            gbc_lblDireccion.gridx = 1;
            gbc_lblDireccion.gridy = 5;
            pnlDatosContacto.add(lblDireccion, gbc_lblDireccion);
            
            txtDireccion = new JTextField();
            GridBagConstraints gbc_txtDireccion = new GridBagConstraints();
            gbc_txtDireccion.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtDireccion.gridwidth = 3;
            gbc_txtDireccion.insets = new Insets(0, 0, 5, 5);
            gbc_txtDireccion.gridx = 2;
            gbc_txtDireccion.gridy = 5;
            pnlDatosContacto.add(txtDireccion, gbc_txtDireccion);
            txtDireccion.setColumns(10);
            
            JLabel lblProvincia = new JLabel("Provincia");
            GridBagConstraints gbc_lblProvincia = new GridBagConstraints();
            gbc_lblProvincia.anchor = GridBagConstraints.WEST;
            gbc_lblProvincia.insets = new Insets(0, 0, 5, 5);
            gbc_lblProvincia.gridx = 1;
            gbc_lblProvincia.gridy = 7;
            pnlDatosContacto.add(lblProvincia, gbc_lblProvincia);
            
            txtProvincia = new JTextField();
            GridBagConstraints gbc_txtProvincia = new GridBagConstraints();
            gbc_txtProvincia.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtProvincia.gridwidth = 3;
            gbc_txtProvincia.insets = new Insets(0, 0, 5, 5);
            gbc_txtProvincia.gridx = 2;
            gbc_txtProvincia.gridy = 7;
            pnlDatosContacto.add(txtProvincia, gbc_txtProvincia);
            txtProvincia.setColumns(10);
            
            JLabel lblCodpostal = new JLabel("C\u00F3digo postal");
            GridBagConstraints gbc_lblCodpostal = new GridBagConstraints();
            gbc_lblCodpostal.anchor = GridBagConstraints.WEST;
            gbc_lblCodpostal.insets = new Insets(0, 0, 0, 5);
            gbc_lblCodpostal.gridx = 1;
            gbc_lblCodpostal.gridy = 9;
            pnlDatosContacto.add(lblCodpostal, gbc_lblCodpostal);
            
            txtCodPostal = new JTextField();
            GridBagConstraints gbc_txtCodPostal = new GridBagConstraints();
            gbc_txtCodPostal.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtCodPostal.gridwidth = 3;
            gbc_txtCodPostal.insets = new Insets(0, 0, 0, 5);
            gbc_txtCodPostal.gridx = 2;
            gbc_txtCodPostal.gridy = 9;
            pnlDatosContacto.add(txtCodPostal, gbc_txtCodPostal);
            txtCodPostal.setColumns(10);
            
            JPanel pnlDatosCuenta = new JPanel();
            GridBagConstraints gbc_pnlDatosCuenta = new GridBagConstraints();
            gbc_pnlDatosCuenta.fill = GridBagConstraints.BOTH;
            gbc_pnlDatosCuenta.insets = new Insets(0, 0, 5, 5);
            gbc_pnlDatosCuenta.gridx = 1;
            gbc_pnlDatosCuenta.gridy = 6;
            pnlRegistro.add(pnlDatosCuenta, gbc_pnlDatosCuenta);
            pnlDatosCuenta.setBorder(new TitledBorder(null, "Datos de la cuenta", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            pnlDatosCuenta.setBackground(Color.WHITE);
            GridBagLayout gbl_pnlDatosCuenta = new GridBagLayout();
            gbl_pnlDatosCuenta.columnWidths = new int[]{30, 0, 171, 0};
            gbl_pnlDatosCuenta.rowHeights = new int[]{15, 0, 10, 0, 10, 0, 15};
            gbl_pnlDatosCuenta.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
            gbl_pnlDatosCuenta.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
            pnlDatosCuenta.setLayout(gbl_pnlDatosCuenta);
            
            JLabel lblUsuario = new JLabel("Usuario");
            GridBagConstraints gbc_lblUsuario = new GridBagConstraints();
            gbc_lblUsuario.anchor = GridBagConstraints.WEST;
            gbc_lblUsuario.insets = new Insets(0, 0, 5, 5);
            gbc_lblUsuario.gridx = 1;
            gbc_lblUsuario.gridy = 1;
            pnlDatosCuenta.add(lblUsuario, gbc_lblUsuario);
            
            txtUsuario = new JTextField();
            GridBagConstraints gbc_txtUsuario = new GridBagConstraints();
            gbc_txtUsuario.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtUsuario.insets = new Insets(0, 0, 5, 0);
            gbc_txtUsuario.gridx = 2;
            gbc_txtUsuario.gridy = 1;
            pnlDatosCuenta.add(txtUsuario, gbc_txtUsuario);
            txtUsuario.setColumns(10);
            
            JLabel lblPassword = new JLabel("Contrase\u00F1a");
            GridBagConstraints gbc_lblPassword = new GridBagConstraints();
            gbc_lblPassword.anchor = GridBagConstraints.WEST;
            gbc_lblPassword.insets = new Insets(0, 0, 5, 5);
            gbc_lblPassword.gridx = 1;
            gbc_lblPassword.gridy = 3;
            pnlDatosCuenta.add(lblPassword, gbc_lblPassword);
            
            txtPass1 = new JPasswordField();
            GridBagConstraints gbc_txtPass1 = new GridBagConstraints();
            gbc_txtPass1.insets = new Insets(0, 0, 5, 0);
            gbc_txtPass1.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtPass1.gridx = 2;
            gbc_txtPass1.gridy = 3;
            pnlDatosCuenta.add(txtPass1, gbc_txtPass1);
            
            JLabel Password2 = new JLabel("Repite tu contrase\u00F1a");
            GridBagConstraints gbc_Password2 = new GridBagConstraints();
            gbc_Password2.insets = new Insets(0, 0, 0, 5);
            gbc_Password2.anchor = GridBagConstraints.WEST;
            gbc_Password2.gridx = 1;
            gbc_Password2.gridy = 5;
            pnlDatosCuenta.add(Password2, gbc_Password2);
            
            txtPass2 = new JPasswordField();
            GridBagConstraints gbc_txtPass2 = new GridBagConstraints();
            gbc_txtPass2.fill = GridBagConstraints.HORIZONTAL;
            gbc_txtPass2.gridx = 2;
            gbc_txtPass2.gridy = 5;
            pnlDatosCuenta.add(txtPass2, gbc_txtPass2);
            
            JPanel panel_1 = new JPanel();
            panel_1.setBorder(null);
            panel_1.setMinimumSize(new Dimension(0, 0));
            panel_1.setBackground(Color.WHITE);
            GridBagConstraints gbc_panel_1 = new GridBagConstraints();
            gbc_panel_1.fill = GridBagConstraints.BOTH;
            gbc_panel_1.insets = new Insets(0, 0, 5, 5);
            gbc_panel_1.gridx = 1;
            gbc_panel_1.gridy = 8;
            pnlRegistro.add(panel_1, gbc_panel_1);
            
            btnAceptar = new JButton("Aceptar");
            panel_1.add(btnAceptar);
            
            btnCancelar = new JButton("Cancelar");
            panel_1.add(btnCancelar);
            if(modificar)
            	btnAceptar.setActionCommand("MODIFICAR_" + String.valueOf(idUsuario));
    }



	public JPanel getPnlRegistro() {
		return pnlRegistro;
	}

	@Override
	public void update() {
		
		
	}

	@Override
	public void SetVisible(boolean visible) {
		this.frmRegistro.setVisible(visible);
		
	}

	@Override
	public void registerListener(ActionListener listener) {
		this.btnAceptar.addActionListener(listener);
		this.btnCancelar.addActionListener(listener);
	}


	public void setTxtNombre(String txtNombre) {
		this.txtNombre.setText(txtNombre);
	}

	public void setTxtDNI(String txtDNI) {
		this.txtDNI.setText( txtDNI);
	}

	public void setTxtApellidos(String txtApellidos) {
		this.txtApellidos.setText(txtApellidos);
	}

	public void setTxtTelefono(String txtTelefono) {
		this.txtTelefono.setText(txtTelefono);
	}

	public void setTxtDireccion(String txtDireccion) {
		this.txtDireccion.setText(txtDireccion);
	}

	public void setTxtProvincia(String txtProvincia) {
		this.txtProvincia.setText(txtProvincia);
	}

	public void setTxtCodPostal(String txtCodPostal) {
		this.txtCodPostal.setText(txtCodPostal);
	}

	public void setTxtEmail(String txtEmail) {
		this.txtEmail.setText(txtEmail);
	}

	public void setTxtUsuario(String txtUsuario) {
		this.txtUsuario.setText(txtUsuario);
	}


	public void dispose(){
		this.frmRegistro.dispose();
	}
	
	public String getTxtDNI() {
		return txtDNI.getText();
	}

	public String getTxtNombre() {
		return txtNombre.getText();
	}

	public String getTxtApellidos() {
		return txtApellidos.getText();
	}

	public String getTxtEmail() {
		return txtEmail.getText();
	}

	public String getTxtTelefono() {
		return txtTelefono.getText();
	}

	public String getTxtDireccion() {
		return txtDireccion.getText();
	}

	public String getTxtProvincia() {
		return txtProvincia.getText();
	}

	public String getTxtCodPostal() {
		return txtCodPostal.getText();
	}

	public String getTxtUsuario() {
		return txtUsuario.getText();
	}

	public char[] getTxtPass1() {
		return txtPass1.getPassword();
	}

	public char[] getTxtPass2() {
		return txtPass2.getPassword();
	}
	
	public String getCmbTipoUsuario() {
		return (String)cmbTipoUsuario.getSelectedItem();
	}
}
